//
//  ViewController.swift
//  JKSwiftSkinning
//
//  Created by 王冲 on 2019/1/28.
//  Copyright © 2019年 JK科技有限公司. All rights reserved.

import UIKit

class ViewController: UIViewController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
       
        view.backgroundColor = UIColor.white;
        
        let item1 = UIBarButtonItem.init(title: "春节", style: UIBarButtonItem.Style.plain, target: self, action: #selector(chunjieClick))
        let item2 = UIBarButtonItem.init(title: "国庆", style: UIBarButtonItem.Style.plain, target: self, action: #selector(guoqingClick))
        let item3 = UIBarButtonItem.init(title: "中秋", style: UIBarButtonItem.Style.plain, target: self, action: #selector(zhongqiuClick))
        
        self.navigationItem.rightBarButtonItems = [item1,item2,item3] as [UIBarButtonItem]
        
        // 添加背景图片
        view.addSubview(bgImageView)
        // 添加Label
        view.addSubview(bgLabel)
        
        showbgImage()
        

    }
    
    lazy var bgLabel:UILabel = {
        
        let bgLabel = UILabel(frame: CGRect.init(x: 100, y: 100, width: 100, height: 100))
        bgLabel.text = "往后余生"
        bgLabel.textAlignment = NSTextAlignment.center
        bgLabel.backgroundColor = UIColor.white
        return bgLabel
        
    }()
    
    lazy var bgImageView : UIImageView = {
    
       let bgImageView = UIImageView(frame: CGRect.init(x: 0, y: 0, width: UIScreen.main.bounds.size.width, height: UIScreen.main.bounds.size.height))
        
        return bgImageView
    }()
    
    // MARK: 显示图片
    func showbgImage() {
        
        // 获取当前主题下，不同类型的图片（背景或者前景）
        bgImageView.image = JKSkinningTool.getSkinImage(type: JKSkinImageType.SkinBack)
       
        // 显示主题下的颜色
        showLabelColor()
    }
    
    // MARK: 显示Label
    func showLabelColor() -> () {
        
        // 获取当前主题下的, 不同类型颜色
        bgLabel.textColor = JKSkinningTool.getSkinColor(type: JKSkinColorType.SkinLabelColor)
    }

    // MARK: - 春节
    @objc func chunjieClick() {

        print("春节")
        JKSkinningTool.saveSkinning(imageName: JKThemeType.Chunjie)
        showbgImage()
    }
    
    // MARK: - 国庆
    @objc func guoqingClick() {
        
        print("国庆")
        JKSkinningTool.saveSkinning(imageName: JKThemeType.Guoqing)
        showbgImage()
    }
    
    // MARK: - 中秋
    @objc func zhongqiuClick() {
        
        print("中秋")
        JKSkinningTool.saveSkinning(imageName: JKThemeType.Zhongqiu)
        showbgImage()
    }

}

